<template>
  <dialog-editor ref="dialog" :width="50"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'
import {mRequest} from '@/utils/request';

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      dataFormConfig: {
        id: {
          hidden: true
        },
        productId: {
          label: '产品',
          type: 'list',
          placeholder: '请选择产品',
          list: [],
          isNeedAdd: true,
          addNewItemFunc: this.addNewProductInfo
        },
        modelId: {
          label: '模具',
          type: 'list',
          filterable: true,
          clearable: true,
          placeholder: '请选择模具',
          list: [],
          isNeedAdd: true,
          addNewItemFunc: this.addNewModel
        },
        price: {
          label: '价格',
          type: 'number'
        },
        productImageId: {
          label: '产品图片',
          type: 'uploadScreenshot',
          imageType: 'uploadProductImage'
        },
        productDrawingId: {
          label: '产品图纸',
          type: 'uploadImage',
          imageType: 'uploadProductPaper'
        },
        successMo: {
          label: '成模',
          type: 'number'
        },
        primaryMo: {
          label: '初模',
          type: 'number'
        },
        menTou: {
          label: '闷头',
          type: 'number'
        },
        louDou: {
          label: '漏斗',
          type: 'number'
        },
        kouZi: {
          label: '口子',
          type: 'number'
        },
        xinZi: {
          label: '芯子',
          type: 'number'
        },
        qiTou: {
          label: '气头',
          type: 'number'
        },
        jiaZi: {
          label: '夹子',
          type: 'number'
        },
        lengQue: {
          label: '冷却',
          type: 'number'
        },
        chongTou: {
          label: '冲头',
          type: 'number'
        },
        qianPian: {
          label: '钳片',
          type: 'number'
        },
        remark: {
          label: '备注',
        },
        status: {
          label: '订单状态',
          type: 'radio',
          radioBorder: false,
          radioList: [
            {text: '待采购', label: 0},
            {text: '采购进行中', label: 2},
            {text: '采购完成', label: 4},
            {text: '采购暂停', label: 6}
          ],
          default: 0
        }
      }
    }
  },
  methods: {
    addNewModel() {
      const cb = (newValue) => {
        this.initModelInfoList('modelId')
        this.dataForm.modelId = newValue.id
      }
      this.$parent.openModelInfoDialog(cb)
    },
    initSupplierId() {
      mRequest('supplierApi/getSupplierList', {}, (res) => {
        this.dataFormConfig['supplierId'].list = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    /**
     * 新增产品
     */
    addNewProductInfo() {
      const cb = (newValue) => {
        this.initProductInfoList()
        this.dataForm.productId = newValue.id
      }
      this.$parent.openProductInfoDialog(cb)
    },
    init(id, property, cb, submitAtFinish = true) {
      this.dataForm.id = id || 0
      //this.initSupplierId()
      this.initModelInfoList('modelId')
      this.initProductInfoList('productId')
      this.$refs.dialog.initDialog({
        submitAtFinish,
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule('purchaseType', 'contractTime', 'deliveryTime', 'status'),
        initApi: 'purchaseApi/purchaseModelInfo',
        saveApi: 'purchaseApi/savePurchaseModel',
        updateApi: 'purchaseApi/updatePurchaseModel',
        objectName: 'purchaseModel',
        submitCallback: cb
      })

      // this.$nextTick(() => {
      //   if (!this.R.isNil(property)) {
      //     Object.keys(property).forEach((key) => {
      //       this.dataForm[key] = property[key]
      //     })
      //   }
      // })
    }
  }
}
</script>
